###
 # @Description: 
 # @Version: 2.0
 # @Autor: gang
 # @Date: 2020-09-10 11:29:33
 # @LastEditors: gang
 # @LastEditTime: 2020-09-16 10:41:53
### 
#!/bin/bash

###
 # @description: 服务主函数
 # @param {type} 
 # @return {type} 
 # @author: gang
###
function main(){
    echo '-----------------------------检测lnmp服务运行状态----------------------'
    php_state
    mysql_state
    nginx_state
    memcached_state
    echo '-----------------------------------------------------------------------'
}

###
 # @description: 监测PHP服务状态
 # @param {type} 
 # @return {type} 
 # @author: gang
###
function php_state(){
    php_status=`systemctl status php-fpm.service | grep -F 'running' | cut -c 20-26`
    if [[ -n ${php_status} ]];
    then
        echo -e '\033[36m php \033[0m服务正在运行中...'
    else
        echo -e '\033[33m php \033[0m服务已停止运行...'
    fi
}

###
 # @description: 监测数据库服务状态
 # @param {type} 
 # @return {type} 
 # @author: gang
###
function mysql_state(){
    mysql_status=`systemctl status mariadb.service | grep -F 'running' | cut -c 20-26`
    if [[ -n ${mysql_status} ]]
    then
        echo -e '\033[36m mysql \033[0m服务正在运行中...'
    else
        echo -e '\043[36m php \043[0m服务已停止运行...'
    fi
}

###
 # @description: 监测nginx服务状态
 # @param {type} 
 # @return {type} 
 # @author: gang
###
function nginx_state(){
    nginx_status=`systemctl status nginx.service | grep -F 'running' | cut -c 20-26`
    if [[ -n ${nginx_status} ]]

        echo -e '\033[36m nginx \033[0m服务正在运行中...'
    else
        echo -e '\043[36m nginx \043[0m服务已停止运行...'
    fi
}

###
 # @description: 监测memcached服务状态
 # @param {type} 
 # @return {type} 
 # @author: gang
###
function memcached_state(){
    memcache_status=`systemctl status memcached.service | grep -F 'running' | cut -c 20-26`
    if [[ -n ${memcache_status} ]]
    then
        echo -e "\033[036m memcached \033[0m服务正在运行..."
    else
        echo -e "\043[36m memcached \043[0m服务已停止运行..."
    fi
}
